package com.biodiv.miracle.support.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @Author: tianquan
 * @CreateTime: 2025-05-28  23:10
 * @Description: io资源工具类
 */
public class ResourceUtils {

    private static final ClassLoader CLASS_LOADER = ClassLoader.getSystemClassLoader();

    public static String convert(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(inputStream, StandardCharsets.UTF_8)
        );
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append(System.lineSeparator());
        }
        return sb.toString();
    }

    /**
     * 获取application.properties文件的内容。
     *
     * @return application.properties文件的内容。
     */
    @Deprecated
    public static Properties getProperties() {
        Properties properties = new Properties();
        try {
            InputStream inputStream = CLASS_LOADER.getResourceAsStream("application.properties");
            if (inputStream == null) {
                return properties;
            }
            properties.load(inputStream);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return properties;
    }

}
